//
//  IdentityVerificationVC.m
//  hnGovernment
//
//  Created by 安仔 on 17/3/6.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "IdentityVerificationVC.h"
#import "SureIdentityVC.h"
#import "AZPickerView.h"
#import "AppDelegate.h"

@interface IdentityVerificationVC ()<UITableViewDelegate, UITableViewDataSource, AZPickerViewDelegate>

@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) UIButton *nextBtn;
@property (nonatomic, strong) NSArray *dataArr;
@property (nonatomic, strong) AZPickerView *myPickerView;
@property (nonatomic, strong) NSArray *pickerViewArray;

@end

@implementation IdentityVerificationVC

- (void) createArrayDate {
    self.dataArr = @[@"姓名", @"身份证号", @"性别", @"名族"];
    self.pickerViewArray = @[@"汉族", @"回族", @"白族", @"傣族", @"满族", @"苗族", @"怒族",
                             @"黎族", @"京族", @"羌族", @"水族", @"侗族", @"土族", @"佤族",
                             @"瑶族", @"畲族", @"彝族", @"壮族", @"藏族", @"阿昌族", @"保安族",
                             @"朝鲜族", @"布朗族", @"布依族", @"德昂族", @"东乡族", @"独龙族", @"高山族",
                             @"哈尼族", @"珞巴族", @"拉祜族", @"僳僳族", @"仡佬族", @"赫哲族", @"景颇族",
                             @"基诺族", @"蒙古族", @"纳西族", @"撒拉族", @"毛南族", @"锡伯族", @"土家族",
                             @"仫佬族", @"普米族", @"门巴族", @"裕固族", @"达斡尔族", @"塔吉克族", @"俄罗斯族",
                             @"鄂伦春族", @"鄂温克族", @"哈萨克族", @"塔塔尔族", @"维吾尔族", @"柯尔克孜族", @"乌孜别克族"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalString(@"身份信息确认");
    self.view.backgroundColor = BackgroundColor;
    
    [self createArrayDate];
    [self createUI];
    
}

- (void) createUI {
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40 * m6Scale, KScreenWidth, 398 * m6Scale) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.backgroundColor = [UIColor whiteColor];
    self.myTableView.scrollEnabled = NO;
    [self.view addSubview:self.myTableView];
    
    //创建NEXT按钮
    self.nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(76 * m6Scale, 510 * m6Scale, 600 * m6Scale, 80 * m6Scale)];
    [self.nextBtn setTitle:NSLocalString(@"下一步") forState:0];
    [self.nextBtn setTitleColor:[UIColor whiteColor] forState:0];
    self.nextBtn.backgroundColor = RGB(210, 235, 255);
    self.nextBtn.layer.cornerRadius = 10 * m6Scale;
    [self.nextBtn addTarget:self action:@selector(nextController) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.nextBtn];
    
    
    //添加民族选择器
    self.myPickerView = [[AZPickerView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight) withContentArr:self.pickerViewArray];
    self.myPickerView.delegate = self;
    self.myPickerView.hidden = YES;
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate.window addSubview:self.myPickerView];
    [delegate.window bringSubviewToFront:self.myPickerView];
    
}

- (void) nextController {
    
    SureIdentityVC *vc = [[SureIdentityVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark AZPickerViewDelegate
- (void)AZPickerViewLeftBtn {
    self.myPickerView.hidden = YES;
}

- (void)AZPickerViewRightBtnWithResult:(NSString *)str {
    self.myPickerView.hidden = YES;
    [SVProgressHUD showSuccessWithStatus:str];
}

#pragma mark UITabelView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100 * m6Scale;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:@"idCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"idCell"];
    }
    if (indexPath.row == 2 || indexPath.row == 3) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    cell.selectionStyle = UIAccessibilityTraitNone;
    cell.textLabel.textColor = RGB(103, 103, 103);
    cell.textLabel.text = self.dataArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 2) {
        UIAlertController * alertController = [UIAlertController alertControllerWithTitle: nil                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
        //添加Button
        [alertController addAction: [UIAlertAction actionWithTitle: @"男" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            NSLog(@"选中男");
        }]];
        [alertController addAction: [UIAlertAction actionWithTitle: @"女" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
            NSLog(@"选中女");
        }]];
        [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
        
        [self presentViewController: alertController animated: YES completion: nil];

    }
    else if (indexPath.row == 3) {
        
        self.myPickerView.hidden = NO;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
